Reflective Visitor Pattern
نویسندگان
چکیده
The Visitor pattern wraps associated operations that are performed on the elements of an object structure into a separate object. It allows the software designer to define new kinds of operations over the object structure without changing the classes of this structure. But a well-known drawback of this standard Visitor structure is that extending the object structure is hard. This paper presents the design and implementation of a flexible Visitor pattern based on the reflection technique, we call it the Reflective Visitor pattern. The reflection technique enables the Visitor to perform the run-time dispatch action on itself. The separation of the run-time dispatch action from the object structure makes any extension to the object structure become easy. It also removes the cyclic dependencies between the Visitor and the object structure, so the reusability and extensibility of the system are improved.
منابع مشابه
Automated reasoning for reflective programs
class Visitor {visit(Object obj) {try {Class obj_class = obj.getClass();String obj_className = obj_class.getName();String methodName = "visit" + obj_className;Class this_class = this.getClass();Method method = this_class.getMethod(methodName, obj_class);method.invoke(this, obj);}catch (NoSuchMethodException e) { }catch (IllegalAccessException e) { }<l...
متن کاملScripting Refactorings in Java to Introduce Design Patterns
Introducing design patterns into a program by hand is tedious and error-prone. Refactorings help but manual tasks still remain: you must understand available refactorings, determine a precise sequence of refactorings to invoke, and perform these tasks repetitively to a laborious degree. We present Reflective Refactoring (R), a Java package to automate the introduction of classical design patter...
متن کاملAuto-generation of Model Visitor Frameworks
The visitor pattern, a well known Gang of Four design pattern, provides a suitable way to add operational behaviour to models. However, as soon as the number of metamodels and visitor implementations start to grow, some of the pattern shortcomings make its usage less convenient. This paper presents how the synergy between the Visitor pattern and MDE has been addressed by two open source project...
متن کاملThe Language of the Visitor Design Pattern
Design patterns have been developed to cope with the vast space of possible different designs within object-oriented systems. One of those classic patterns is the Visitor Pattern that is used for representing an operation to be performed on the elements of an object structure. We present a mapping from the Visitor Pattern to a grammar that defines the set of visit sequences that can be performe...
متن کاملVisitor-Oriented Programming
Multiple dispatching and the visitor pattern are approaches to making object-oriented programs more extensible. Both have a flavor of pattern matching, thereby moving objectoriented programming closer to functional programming. The key idea of these approaches can be crystallized as a notion of visitor which lies between functions and objects. Can this idea be developed into a new form of visit...
متن کامل